package com.echo.controller;

import com.echo.context.WisUserIdContext;
import com.echo.result.ResultVO;
import com.echo.service.IExamAnalysisService;
import com.echo.vo.AllObjectDetailData;
import com.echo.vo.ExamIdAnaDataVo;
import com.echo.vo.ObjectDataVo;
import com.fasterxml.jackson.core.JsonProcessingException;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@Tag(name = "Data APIs")
@RequestMapping("/api/data")
public class DataController {
    @Autowired
    private IExamAnalysisService examAnalysisService;
    @GetMapping("/objectDatailData")
    @Operation(summary ="利用传来的科目名称获得数据去渲染表格")
    ResultVO<ObjectDataVo> getObjectDetailData(@RequestParam String subject){
        // 这里前端传来字段名，然后这里返回关于该学科的分析结果【掌握程度的不同占比】
        // 如：subject 语文
        // 返回：阅读理解 20%
        //      作文     30%
        String userId = WisUserIdContext.getUserIdContext();
        ObjectDataVo ObjectDataVo =  examAnalysisService.getObjectDatailData(subject);
        ResultVO<ObjectDataVo> resultVO=new ResultVO<>(0,"获取某科目的数据成功",ObjectDataVo);
        return resultVO;
    }
    //传入某一张试卷的id，从而得到该试卷的分析情况[1.综合不同时期的分析情况，2.卷子的知识情况】
    @GetMapping("/examIdAnalysisData")
    @Operation(summary ="根据试卷id获得试卷的分析和历史分析")
    ResultVO<ExamIdAnaDataVo>  getExamIdAnalysisData(@RequestParam(required = false) String examId) throws IOException {
        ExamIdAnaDataVo examIdAnaDataVo=examAnalysisService.getExamIdAnalysisData(examId);
        ResultVO<ExamIdAnaDataVo> examIdAnaDataVoResultVO=new ResultVO<>(0,"获取数据成功",examIdAnaDataVo);
        return examIdAnaDataVoResultVO;
    }
     //查看用户的综合分析，不用时间了，各个学科的
    @GetMapping("/AllObjectDatailData")
    @Operation(summary ="综合分析得到数据")
    ResultVO<AllObjectDetailData> getAllObjectDetailData() throws JsonProcessingException {
        AllObjectDetailData allObjectDetailData= examAnalysisService.getAllObjectDetailData();
        ResultVO<AllObjectDetailData> resultVO=new ResultVO<>(0,"获取数据成功",allObjectDetailData);
        return resultVO;
    }
}

